package com.sphd.emanu.mvp;

import android.widget.Toast;

import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.sphd.emanu.config.Constant;
import com.sphd.emanu.retrofitUtil.EmanuService;
import com.sphd.emanu.retrofitUtil.HttpApi;
import com.sphd.emanu.utils.GsonUtil;
import com.sphd.emanu.utils.retrofitError.ExceptionEngine;
import com.wzutils.L;
import com.wzutils.T;

import java.util.Map;

import retrofit2.Response;

/**
 * MVPPlugin
 * 邮箱 784787081@qq.com
 */

public class BasePresenterImpl<V extends BaseView> implements BasePresenter<V> {
    protected V mView;
    public HttpApi httpApi;
    public EmanuService emanuService;



    @Override
    public void attachView(V view) {
        mView = view;

        httpApi = HttpApi.getInstance(Constant.HTTPTITLE);
        emanuService = httpApi.getService(EmanuService.class);
    }

    @Override
    public void detachView() {
        mView = null;
    }

    @Override
    public void Error(Throwable t) {
        L.e(t.toString()+"-----"+t.getMessage());
        mView.dissProgressDialog();
        T.showShort(mView.getContext(), ExceptionEngine.handleException(t).toString());
    }

    public int res(Response<JsonObject> response) {
        return response.body().get("resStatus").getAsInt();
    }

}
